#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

int cmp(const void* a, const void* b)
{
    return *(int*)a > *(int*)b;
}

int* removeDuplicates(int* nums, int numsSize, int* returnSize) {
    int count = 0;
    for (int i = 1; i < numsSize; ++i)
    {
        if (nums[i] != nums[count])
            nums[++count] = nums[i];
    }
    ++count;
    *returnSize = count;
    return nums;
}

int Findduplicates(int* nums, int numsSize)
{
    int i, sum = 0;
    for (i = 0; i < numsSize; i++)
    {
        sum ^= nums[i];
    }
    for (i = 1; i <= numsSize + 1; i++)
    {
        sum ^= i;
    }
    return sum;
}

int* findErrorNums(int* nums, int numsSize, int* returnSize) {
    qsort(nums, numsSize, sizeof(int), cmp);
    int* tmp = (int*)malloc(sizeof(int) * 2);
    int sum1 = 0, sum2 = 0;
    int i = 0;
    for (i = 0; i < numsSize; i++)
    {
        sum1 += nums[i];
    }
    for (i = 1; i < numsSize + 1; i++)
    {
        sum2 += i;
    }
    nums = removeDuplicates(nums, numsSize, &numsSize);
    int ret = Findduplicates(nums, numsSize);
    int rem = sum2 - sum1;
    tmp[0] = ret - rem;
    tmp[1] = ret;
    *returnSize = 2;
    return tmp;
}

int main()
{
    int a[] = { 1,2,2,4 };
    int size = 4;
    removeDuplicates(a, 4, &size);
    int ret = Findduplicates(a, size);
    findErrorNums(a, 4, &size);
    return 0;
}